<?php 
defined('IN_SITE') or exit('Access Denied');


/*require_once MOD_ROOT.'html/html.class.php';
$html = new html();*/

require_once MOD_ROOT.'codex/codex.class.php';
$codex = new codex();

switch($action)
{
	case 'category':
		
		break;
	
	case 'content':
	
		$data = $db->select("SELECT `codexid`,`url` FROM `".DB_PRE."codex` ORDER BY `codexid`");
		foreach($data as $r)
		{
			// 返回URL地址
			$showurl = $codex->url($r['codexid']);
			if(!$db->get_one("SELECT codexid FROM `".DB_PRE."codex` WHERE `codexid`='$r[codexid]' AND `url`='$showurl'"))
			{
				$db->query("UPDATE `".DB_PRE."codex` SET url='$showurl' WHERE `codexid`='$r[codexid]'");
			}
		}
		
		if($SETTING['ishtml'])
		{
			$message = "URL更新完成！开始更新内容页 ...";
			$forward = '?module=codex&file=html';
		}
		else
		{
			$message = "内容URL更新完成！";
			$forward = '?module=codex';
		}
		showmessage($message, $forward);
		break;
	
	default:
		include 'templates/url.tpl.php';
} 
 

/*if($dosubmit)
{
	if($type == 'lastinput')
	{
		$offset = 0;
	}
	else
	{
		$page = max(intval($page), 1);
		$offset = $pagesize*($page-1);
	}*/
	
/*	$where = ' WHERE status=99 ';
	$order = 'ASC';
	
	if(!isset($firest) && is_array($catids) && $catids[0] > 0) 
	{
		cache_write('url_show_'.$_userid.'.php', $catids);
		$catids = implodeids($catids);
		$where .= " AND catid IN($catids) ";
		$firest = 1;
	}
	elseif($firest)
	{
		$catids = cache_read('url_show_'.$_userid.'.php');
		$catids = implodeids($catids);
		$where .= " AND catid IN($catids) ";
	}
	else
	{
		$firest = 0;
	}

	if(!isset($total) && $type != 'lastinput')
	{
		$total = cache_count("SELECT COUNT(*) AS `count` FROM `".DB_PRE."content` $where");
		$pages = ceil($total/$pagesize);
		$start = 1;
	}
	$data = $db->select("SELECT `contentid`, `islink`, `url` FROM `".DB_PRE."content` ORDER BY `contentid`");
	foreach($data as $r)
	{
		if($r['islink']) continue;
		
		// 返回URL地址
		$showurl = $url->show($r['contentid']);
		
		$url->update($r['contentid'],$showurl);
		/*if(!is_a($c, 'content'))
		{
			require MOD_ROOT.'content/content.class.php';
			$c = new content();	
		}
		$c->search_api($r['contentid']);
	}
	if($pages > $page)
	{
		$page++;
		$creatednum = $offset + count($data);
		$percent = round($creatednum/$total, 2)*100;
		$message = "共需更新 <font color='red'>$total</font> 条信息<br />已完成 <font color='red'>{$creatednum}</font> 条（<font color='red'>{$percent}%</font>）";
		$forward = $start ? "?module=$module&file=url&type=$type&dosubmit=1&firest=$firest&action=$action&fromid=$fromid&toid=$toid&fromdate=$fromdate&todate=$todate&pagesize=$pagesize&page=$page&pages=$pages&total=$total" : preg_replace("/&page=([0-9]+)&pages=([0-9]+)&total=([0-9]+)/", "&page=$page&pages=$pages&total=$total", URL);;
	}
	else
	{
		
	}
	
	
	
	
	
}
else
{
	require_once MOD_ROOT.'category/category.class.php';
	$cat = new category($module);
	$cat->repair();
	include ('url.tpl.php');
}*/
?>